package com.cy.pj.sys.service.impl;

import com.cy.pj.common.annotation.RequiredLog;
import com.cy.pj.common.annotation.RequiredTime;
import com.cy.pj.sys.dao.SysNoticeDao;
import com.cy.pj.sys.pojo.SysNotice;
import com.cy.pj.sys.service.SysNoticeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Service;
import java.util.List;


@Service
public class SysNoticeServiceImpl implements SysNoticeService {
    //工厂模式，用SLF4J包中的方法才能创建日志，进行日志记录：
    private static final Logger log=
            //通过工厂创建日志对象
            LoggerFactory.getLogger(SysNoticeServiceImpl.class);
    @Autowired
    private SysNoticeDao sysNoticeDao;

    @RequiredLog(operation = "查询公告列表")
    @Override
    public int saveNotice(SysNotice notice) {
        int rows = sysNoticeDao.insertNotice(notice);
        return rows;
    }

    @RequiredLog(operation = "查询公告列表")
    @Override
    public List<SysNotice> findNotices(SysNotice notice) {
        List<SysNotice> list = sysNoticeDao.selectNotices(notice);
        return list;
    }

    @Override
    public int deleteById(Long... ids) {
        int rows= sysNoticeDao.deleteById(ids);
        if(rows==0)throw new RuntimeException("记录可能已经不存在");
        return rows;
    }

    @RequiredLog(operation = "基于id查询通知")
    @RequiredTime
    @Override
    public SysNotice findById(Long id) {
        SysNotice notice = sysNoticeDao.selectById(id);
        return notice;
    }

    @Override
    public int updateNotice(SysNotice notice) {
        int rows = sysNoticeDao.updateNotice(notice);
        return rows;
    }
}
